package com.yangjiaying.kebiao.Utils;

import com.yangjiaying.kebiao.config.Constant;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.jsoup.Jsoup;

import java.io.IOException;

public class CookieUtlis {
    /**
     * 获取__VIEWSTATE
     * @param cookie
     * @return __VIEWSTATE
     * @throws UnsupportedOperationException
     * @throws IOException
     */
    public static String getViewState(String cookie)
            throws UnsupportedOperationException,
            IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .header("Cookie", cookie)
                .header("Referer", Constant.jiaoyuanguanwangURL)
                .url("http://jw.svtcc.edu.cn/default2.aspx")
                .build();
        Response response = okHttpClient.newCall(request).execute();
        String s = response.body().string();
        String viewstate = Jsoup.parse(s).select("input[name=__VIEWSTATE]").val();
        return viewstate;
    }

}
